import {
	mapMutations
} from 'vuex'
export default {
	...mapMutations([
		'upUserInfo'
	]),
	toFollowUser() {
		uni.navigateTo({
			url: '/pages/my/followUser'
		})
	},
	toFans() {
		uni.navigateTo({
			url: '/pages/my/fans'
		})
	},
	toNotificationLike() {
		uni.navigateTo({
			url: '/pages/index/notificationLike'
		})
	},
	upAvatar() {
		let that = this
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				let avatar = res.data.filePath
				that.$httpRequest.request({
					that: that,
					url: 'wechat/editUserInfo',
					params: {
						avatar: avatar,
					},
					success: res => {
						// that.$toast.alert({
						// 	content: res.message,
						// 	callback: result => {

						// 	}
						// })
						if (res.code === that.$httpConfig.SUCCESS_CODE) {
							that.userInfo.avatar = avatar
							that.upUserInfo(that.userInfo)
						} else {

						}
					}
				})
			}
		})
	},
	longClick(id, index) {
		let that = this
		if (that.current == 0) {

			uni.showActionSheet({
				itemList: ['删除该作品'],
				success: function(res) {
					if (res.tapIndex == 0) {
						that.$httpRequest.get({
							that: that,
							url: 'wechat/deleteInformation',
							params: {
								id: id
							},
							success: res => {
								if (res.code === that.$httpConfig.SUCCESS_CODE) {
									that.list.splice(index, 1)
								}
							}
						})
					} else {


					}
					// console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
				},
				fail: function(res) {
					// console.log(res.errMsg);
				}
			});
			wx.vibrateShort();
		}
	},
	leftClick() {
		this.$refs.popup.show({
			message: "从上往下滑动"
		});
	},
	changeItem(index) {
		this.page = 1;
		this.list = [];
		this.current = index;
		if (this.current === 0) {
			this.getPageList();
		} else if (this.current === 1) {
			this.getMyCollectList()
		} else if (this.current === 2) {
			this.getMyFavoriteList()
		}
	},
	changeType(item) {
		this.type = item.id
		this.page = 1;
		this.list = [];
		this.getPageList();
	},
	toSetting() {
		uni.navigateTo({
			url: '/pages/my/setting'
		})
	},
	toExplain() {
		uni.navigateTo({
			url: '/pages/my/explain'
		})
	},
	toUser() {
		uni.navigateTo({
			url: '/pages/my/user'
		})
	},
	getPageList() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'wechat/getMyInformationList',
			params: {
				type: that.type,
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		})
	},
	getMyCollectList() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'wechat/getMyCollectList',
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		})
	},
	getMyFavoriteList() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'wechat/getMyFavoriteList',
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		})
	},
	getServiceTel() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'Setting/getServiceTel',
			params: {

			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.serviceTel = res.data
				} else {

				}
			}
		})
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/info',
			method: 'get',
			params: {

			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
					console.log(that.userInfo)
					// setTimeout(function () {
					// 		    uni.hideLoading();
					// 		}, 200);
				} else {
					that.upUserInfo({})
				}
			}
		}, false)
	},
	toUrl(id) {
		switch (id) {

			case 1:
				//我发布的
				uni.navigateTo({
					url: '/pages/my/mySend'
				})
				break
			case 2:
				// 我买到的
				uni.navigateTo({
					url: '/pages/my/myOrder'
				})
				break
			case 3:
				// 我卖出的
				uni.navigateTo({
					url: '/pages/my/mySalesOrder'
				})
				break
			case 4:
				//系统设置
				uni.navigateTo({
					url: '/pages/my/history'
				})
				break
			default:
				break
		}
	},
	handlerNav(type) {
		switch (type) {
			case 0:
				// 商家信息
				uni.navigateTo({
					url: '/pages/my/explain'
				})
				break
			case 1:
				// 我的优惠券
				uni.navigateTo({
					url: '/pages/my/purpose'
				})
				break
			case 2:
				// 我的分享
				uni.navigateTo({
					url: '/pages/my/myShare'
				})
				break
			case 3:
				//系统设置
				uni.navigateTo({
					url: '/pages/my/setting'
				})
				break
			case 4:
				//系统设置
				uni.navigateTo({
					url: '/pages/my/address'
				})
				break
			default:
				break
		}
	},




}